package com.sdkx.app.fragment;
//航线的2级菜单
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.sdkx.app.R;
import com.sdkx.app.activitys.MainActivity;
import com.sdkx.app.adapter.MainMenuAdapter;

public class RoutesFragmentView1 extends BaseFragment {

    private View rootView;
    //航线管理二级目录
    private String[] CourseList = {"航线列表", "当前航线"};
    private ListView lvGroup;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (null != rootView) {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (null != parent) {
                parent.removeView(rootView);
            }
        } else {
            initView(inflater, container);
        }
        return rootView;
    }
    private void initView(LayoutInflater inflater, ViewGroup container) {
        rootView = inflater.inflate( R.layout.fragment_menu_routelist, container,
                false);
        lvGroup = (ListView) rootView.findViewById(R.id.lvGroup);
        MainMenuAdapter menuadapter = new MainMenuAdapter(getActivity(), CourseList);
        lvGroup.setAdapter(menuadapter);
        lvGroup.setOnItemClickListener(new MyMainMenuAdapterViewListener());
        //返回上一级点击事件
        Button tv_all_air_spaces = (Button) rootView.findViewById(R.id.tv_all_air_spaces);

        //返回上一级按钮
        tv_all_air_spaces.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // ((MainActivity)getActivity()).ShowMainMenu(0);
                goBack();

            }
        });
        //航线列表


    }
    //二级菜单点击事件
    private class MyMainMenuAdapterViewListener implements AdapterView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position){
                case 0:
                   // ((MainActivity)getActivity()).ShowMainMenu(position+11); //显示对应的二级菜单
                    startFragment(RoutesFragmentView2.class);
                    break;
                case 1:
                    Bundle bundle = new Bundle();
                    bundle.putString("mode","current");
                    startFragment(RouteEditFragment.class,bundle);
                    break;

            }

        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        rootView = null;
    }

}
